package com.ccp.dev.qbdms.tag;

import com.ccp.dev.core.basic.api.ISysUser;
import com.ccp.dev.core.basic.util.ContextUtil;
import com.ccp.dev.core.util.AppUtil;
import com.ccp.dev.core.util.DateFormatUtil;
import com.ccp.dev.core.util.StringPool;
import com.ccp.dev.extend.service.ExtendSysOrgService;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.SimpleTagSupport;
import java.util.Date;

/**
 * @author 创新中心-王明亮
 * @description 填报信息标签
 */
public class FillDeptTag extends SimpleTagSupport {

    /**
     * id
     */
    private String id;

    /**
     * 名称
     */
    private String name;

    /**
     * 样式
     */
    private String css;

    /**
     * 跨列数
     */
    private String colspan;


    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getCss() {
        return css;
    }

    public void setCss(String css) {
        this.css = css;
    }

    public String getColspan() {
        return colspan;
    }

    public void setColspan(String colspan) {
        this.colspan = colspan;
    }

    @Override
    public void doTag() throws JspException {
        JspWriter out = getJspContext().getOut();
        try {
            ExtendSysOrgService extendSysOrgService = AppUtil.getBean(ExtendSysOrgService.class);
            ISysUser currentUser = ContextUtil.getCurrentUser();
            String fillDept = extendSysOrgService.getTenOrg(currentUser.getUserId()).getOrgName();
            String fillMan = currentUser.getFullName();
            String fillDate = DateFormatUtil.format(new Date(), StringPool.DATE_FORMAT_DATE);
            StringBuffer stringBuffer = new StringBuffer("<div ");
            if (null != id) {
                stringBuffer.append("id=\"").append(id).append("\" ");
            }
            if (null != name) {
                stringBuffer.append("name=\"").append(name).append("\" ");
            }
            if (null != css) {
                stringBuffer.append("class=\"").append(css).append("\" ");
            }
            if (null != colspan) {
                stringBuffer.append("colspan=\"").append(colspan).append("\" ");
            }
            stringBuffer.append(">");
            stringBuffer.append("<span class=\"qbdms-TBinformation\">填报信息:</span>");
            stringBuffer.append("<span class=\"qbdms-TBinformationText\">【").append(fillDept).append(" | ").append(fillMan).append(" | ").append(fillDate).append("】</span>");
            stringBuffer.append("</div>");
            out.print(stringBuffer);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
